package cn.zd.demo1;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class ButtonActivity extends AppCompatActivity implements View.OnClickListener {

    private Button button_status;
    private Button button_enable;
    private Button button_disable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Toast.makeText(this,this.getClass().getName(),Toast.LENGTH_LONG).show();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);
        button_enable = findViewById(R.id.btn_enable);
        button_disable = findViewById(R.id.btn_disable);
        button_status = findViewById(R.id.btn_status);
        button_enable.setOnClickListener(this);
        button_disable.setOnClickListener(this);
        button_status.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_enable) {
            Toast.makeText(this,"状态按钮被启用",Toast.LENGTH_LONG).show();
            button_status.setBackgroundColor(Color.GREEN);
            button_status.setEnabled(true);
        } else if (v.getId() == R.id.btn_disable) {
            button_status.setBackgroundColor(Color.GRAY);
            Toast.makeText(this,"状态按钮被禁用",Toast.LENGTH_LONG).show();
            button_status.setEnabled(false);
        } else if (v.getId() == R.id.btn_status) {
            Toast.makeText(this,"状态按钮被点击了",Toast.LENGTH_LONG).show();
        }
    }
}